package com.mmall.util;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * Created by root on 18-4-7.
 */
public class PropertyUtil {
    private static Logger log = LoggerFactory.getLogger(PropertyUtil.class);
    private  static Properties properties = new Properties();

    static {
        String fileName = "mmall.properties";
        try {
            properties.load(new InputStreamReader(PropertyUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"));
        } catch (IOException e) {
            log.error("can't load mmall.properties .", e);
        }

    }

    public static String getProperty(String key){
        if (StringUtils.isBlank(key)){
            return null;
        }
        String value = properties.getProperty(key.trim());
        return value.trim();
    }

    public static String getProperty(String key, String defaultValue){
        String value = getProperty(key);
        if (StringUtils.isBlank(value)){
            return defaultValue;
        } else {
            return defaultValue;
        }
    }


    public static String getFtpHost(){
        return getProperty("ftp.server.http.prefix");
    }

    public static void main(String[] args) {
        String value1 =  getProperty("test");
        System.out.println("dfsdfsdf"+value1);
    }


}
